<?php

namespace Kiri\Events;


use Exception;
use Kiri\Di\Interface\InjectTargetInterface;

#[\Attribute]
readonly class EventListener implements InjectTargetInterface
{


    /**
     * @param string $event
     * @throws Exception
     */
    public function __construct(public string $event)
    {
    }


    /**
     * @param string $class
     * @return void
     * @throws Exception
     */
    public function dispatch(string $class): void
    {
        // TODO: Implement dispatch() method.
        $target = \Kiri::getDi()->getReflectionClass($class)->newInstanceWithoutConstructor();

        on($this->event, [$target, "onHandler"]);
    }

}